void
normalGapGrid(Monitor *m, uint gappo, uint gappi)
{
    unsigned int i, n, cx, cy, cw, ch, cols, rows;
    Client *c;

    for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++);
    if (n == 0) return;
    if (n == 2) rows = 1, cols = 2;
    else {
    	for (cols = 0; cols <= n / 2; cols++)
		    if (cols * cols >= n)
			      break;
    	rows = (cols && (cols - 1) * cols >= n) ? cols - 1 : cols;
    }
    // ch = (m->wh) / rows;
    // cw = (m->ww) / cols;
    ch = (m->wh - 2 * gappo - (rows - 1) * gappi) / rows;
    cw = (m->ww - 2 * gappo - (cols - 1) * gappi) / cols;

    for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
    	// cx = m->wx + (i % cols) * (cw);
	    // cy = m->wy + (i / cols) * (ch);
    	cx = m->wx + (i % cols) * (cw + gappi);
	    cy = m->wy + (i / cols) * (ch + gappi);

	    resize(c,
	           cx + gappo,
	           cy + gappo,
    	       cw - 2 * c->bw,
	           ch - 2 * c->bw,
	           0);
    	i++;
    }
}

void
grid(Monitor *m) {
  normalGapGrid(m, m->gappx, m->gappx);
}
